<a href='https://github.com/angular/angular.js/edit/v1.5.x/src/ngSanitize/filter/linky.js?message=docs(linky)%3A%20describe%20your%20change...#L3' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this Doc</a>



<a href='https://github.com/angular/angular.js/tree/v1.5.8/src/ngSanitize/filter/linky.js#L3' class='view-source pull-right btn btn-primary'>
  <i class="glyphicon glyphicon-zoom-in">&nbsp;</i>View Source
</a>


<header class="api-profile-header">
  <h1 class="api-profile-header-heading">linky</h1>
  <ol class="api-profile-header-structure naked-list step-list">
    
    <li>
      - filter in module <a href="api/ngSanitize">ngSanitize</a>
    </li>
  </ol>
</header>



<div class="api-profile-description">
  <p>Finds links in text input and turns them into html links. Supports <code>http/https/ftp/mailto</code> and
plain email address links.</p>
<p>Requires the <a href="api/ngSanitize"><code>ngSanitize</code></a> module to be installed.</p>

</div>






<div>
  

  
  <h2>Usage</h2>
  <h3>In HTML Template Binding</h3>
  
    <code>&lt;span ng-bind-html=&quot;linky_expression | linky&quot;&gt;&lt;/span&gt;</code>
  

  <h3>In JavaScript</h3>
  <pre><code>$filter(&#39;linky&#39;)(text, target, attributes)</code></pre>

  
<section class="api-section">
  <h3>Arguments</h3>

<table class="variables-matrix input-arguments">
  <thead>
    <tr>
      <th>Param</th>
      <th>Type</th>
      <th>Details</th>
    </tr>
  </thead>
  <tbody>
    
    <tr>
      <td>
        text
        
        
      </td>
      <td>
        <a href="" class="label type-hint type-hint-string">string</a>
      </td>
      <td>
        <p>Input text.</p>

        
      </td>
    </tr>
    
    <tr>
      <td>
        target
        
        
      </td>
      <td>
        <a href="" class="label type-hint type-hint-string">string</a>
      </td>
      <td>
        <p>Window (<code>_blank|_self|_parent|_top</code>) or named frame to open links in.</p>

        
      </td>
    </tr>
    
    <tr>
      <td>
        attributes
        
        <div><em>(optional)</em></div>
      </td>
      <td>
        <a href="" class="label type-hint type-hint-object">object</a><a href="" class="label type-hint type-hint-function">function(url)</a>
      </td>
      <td>
        <p>Add custom attributes to the link element.</p>
<p>   Can be one of:</p>
<ul>
<li><code>object</code>: A map of attributes</li>
<li><p><code>function</code>: Takes the url as a parameter and returns a map of attributes</p>
<p>If the map of attributes contains a value for <code>target</code>, it overrides the value of
the target parameter.</p>
</li>
</ul>

        
      </td>
    </tr>
    
  </tbody>
</table>

</section>
  
  <h3>Returns</h3>
<table class="variables-matrix return-arguments">
  <tr>
    <td><a href="" class="label type-hint type-hint-string">string</a></td>
    <td><p>Html-linkified and <a href="api/ngSanitize/service/$sanitize">sanitized</a> text.</p>
</td>
  </tr>
</table>


  
  <h2 id="example">Example</h2><p>

<div>
  <plnkr-opener example-path="examples/example-example110"></plnkr-opener>

  <div class="runnable-example"
      path="examples/example-example110"
      module="linkyExample"
      deps="angular-sanitize.js">

  
    <div class="runnable-example-file" 
      name="index.html"
      language="html"
      type="html">
      <pre><code>&lt;div ng-controller=&quot;ExampleController&quot;&gt;&#10;Snippet: &lt;textarea ng-model=&quot;snippet&quot; cols=&quot;60&quot; rows=&quot;3&quot;&gt;&lt;/textarea&gt;&#10;&lt;table&gt;&#10;  &lt;tr&gt;&#10;    &lt;th&gt;Filter&lt;/th&gt;&#10;    &lt;th&gt;Source&lt;/th&gt;&#10;    &lt;th&gt;Rendered&lt;/th&gt;&#10;  &lt;/tr&gt;&#10;  &lt;tr id=&quot;linky-filter&quot;&gt;&#10;    &lt;td&gt;linky filter&lt;/td&gt;&#10;    &lt;td&gt;&#10;      &lt;pre&gt;&amp;lt;div ng-bind-html=&quot;snippet | linky&quot;&amp;gt;&lt;br&gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&#10;    &lt;/td&gt;&#10;    &lt;td&gt;&#10;      &lt;div ng-bind-html=&quot;snippet | linky&quot;&gt;&lt;/div&gt;&#10;    &lt;/td&gt;&#10;  &lt;/tr&gt;&#10;  &lt;tr id=&quot;linky-target&quot;&gt;&#10;   &lt;td&gt;linky target&lt;/td&gt;&#10;   &lt;td&gt;&#10;     &lt;pre&gt;&amp;lt;div ng-bind-html=&quot;snippetWithSingleURL | linky:&#39;_blank&#39;&quot;&amp;gt;&lt;br&gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&#10;   &lt;/td&gt;&#10;   &lt;td&gt;&#10;     &lt;div ng-bind-html=&quot;snippetWithSingleURL | linky:&#39;_blank&#39;&quot;&gt;&lt;/div&gt;&#10;   &lt;/td&gt;&#10;  &lt;/tr&gt;&#10;  &lt;tr id=&quot;linky-custom-attributes&quot;&gt;&#10;   &lt;td&gt;linky custom attributes&lt;/td&gt;&#10;   &lt;td&gt;&#10;     &lt;pre&gt;&amp;lt;div ng-bind-html=&quot;snippetWithSingleURL | linky:&#39;_self&#39;:{rel: &#39;nofollow&#39;}&quot;&amp;gt;&lt;br&gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&#10;   &lt;/td&gt;&#10;   &lt;td&gt;&#10;     &lt;div ng-bind-html=&quot;snippetWithSingleURL | linky:&#39;_self&#39;:{rel: &#39;nofollow&#39;}&quot;&gt;&lt;/div&gt;&#10;   &lt;/td&gt;&#10;  &lt;/tr&gt;&#10;  &lt;tr id=&quot;escaped-html&quot;&gt;&#10;    &lt;td&gt;no filter&lt;/td&gt;&#10;    &lt;td&gt;&lt;pre&gt;&amp;lt;div ng-bind=&quot;snippet&quot;&amp;gt;&lt;br&gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;/td&gt;&#10;    &lt;td&gt;&lt;div ng-bind=&quot;snippet&quot;&gt;&lt;/div&gt;&lt;/td&gt;&#10;  &lt;/tr&gt;&#10;&lt;/table&gt;</code></pre>
    </div>
  
    <div class="runnable-example-file" 
      name="script.js"
      language="js"
      type="js">
      <pre><code>angular.module(&#39;linkyExample&#39;, [&#39;ngSanitize&#39;])&#10;.controller(&#39;ExampleController&#39;, [&#39;$scope&#39;, function($scope) {&#10;  $scope.snippet =&#10;    &#39;Pretty text with some links:\n&#39;+&#10;    &#39;http://angularjs.org/,\n&#39;+&#10;    &#39;mailto:us@somewhere.org,\n&#39;+&#10;    &#39;another@somewhere.org,\n&#39;+&#10;    &#39;and one more: ftp://127.0.0.1/.&#39;;&#10;  $scope.snippetWithSingleURL = &#39;http://angularjs.org/&#39;;&#10;}]);</code></pre>
    </div>
  
    <div class="runnable-example-file" 
      name="protractor.js"
      type="protractor"
      language="js">
      <pre><code>it(&#39;should linkify the snippet with urls&#39;, function() {&#10;  expect(element(by.id(&#39;linky-filter&#39;)).element(by.binding(&#39;snippet | linky&#39;)).getText()).&#10;      toBe(&#39;Pretty text with some links: http://angularjs.org/, us@somewhere.org, &#39; +&#10;           &#39;another@somewhere.org, and one more: ftp://127.0.0.1/.&#39;);&#10;  expect(element.all(by.css(&#39;#linky-filter a&#39;)).count()).toEqual(4);&#10;});&#10;&#10;it(&#39;should not linkify snippet without the linky filter&#39;, function() {&#10;  expect(element(by.id(&#39;escaped-html&#39;)).element(by.binding(&#39;snippet&#39;)).getText()).&#10;      toBe(&#39;Pretty text with some links: http://angularjs.org/, mailto:us@somewhere.org, &#39; +&#10;           &#39;another@somewhere.org, and one more: ftp://127.0.0.1/.&#39;);&#10;  expect(element.all(by.css(&#39;#escaped-html a&#39;)).count()).toEqual(0);&#10;});&#10;&#10;it(&#39;should update&#39;, function() {&#10;  element(by.model(&#39;snippet&#39;)).clear();&#10;  element(by.model(&#39;snippet&#39;)).sendKeys(&#39;new http://link.&#39;);&#10;  expect(element(by.id(&#39;linky-filter&#39;)).element(by.binding(&#39;snippet | linky&#39;)).getText()).&#10;      toBe(&#39;new http://link.&#39;);&#10;  expect(element.all(by.css(&#39;#linky-filter a&#39;)).count()).toEqual(1);&#10;  expect(element(by.id(&#39;escaped-html&#39;)).element(by.binding(&#39;snippet&#39;)).getText())&#10;      .toBe(&#39;new http://link.&#39;);&#10;});&#10;&#10;it(&#39;should work with the target property&#39;, function() {&#10; expect(element(by.id(&#39;linky-target&#39;)).&#10;     element(by.binding(&quot;snippetWithSingleURL | linky:&#39;_blank&#39;&quot;)).getText()).&#10;     toBe(&#39;http://angularjs.org/&#39;);&#10; expect(element(by.css(&#39;#linky-target a&#39;)).getAttribute(&#39;target&#39;)).toEqual(&#39;_blank&#39;);&#10;});&#10;&#10;it(&#39;should optionally add custom attributes&#39;, function() {&#10; expect(element(by.id(&#39;linky-custom-attributes&#39;)).&#10;     element(by.binding(&quot;snippetWithSingleURL | linky:&#39;_self&#39;:{rel: &#39;nofollow&#39;}&quot;)).getText()).&#10;     toBe(&#39;http://angularjs.org/&#39;);&#10; expect(element(by.css(&#39;#linky-custom-attributes a&#39;)).getAttribute(&#39;rel&#39;)).toEqual(&#39;nofollow&#39;);&#10;});</code></pre>
    </div>
  

    <iframe class="runnable-example-frame" src="examples/example-example110/index.html" name="example-example110"></iframe>
  </div>
</div>


</p>

</div>


